package com.ing.mytest;
import com.ing.mytest.dao.DSlogDAO;
import com.ing.mytest.model.DSlogline;

import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.util.StopWatch;

	/**
	 * Handles requests for the application test page.
	 */
	@Controller
	public class TestController {

		@Autowired
		private DSlogDAO dsllDAO;
		
		private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
		
		@RequestMapping(value="/test")
		public ModelAndView listDsll(ModelAndView model) throws IOException{
			StopWatch s = new StopWatch();
			s.start();
		    List<DSlogline> listDsll = dsllDAO.list();
		    s.stop();
		    
		    List<String> dsservicetypename = dsllDAO.dsServiceTypeName();
		    int dsnumsessions = dsllDAO.dsNumSessions();
		    List<String> dsdrivernames = dsllDAO.dsDriverNames();
		    List<String> dsenginenames = dsllDAO.dsEngineNames(); 
		    List<String> dsinfoage = dsllDAO.dsInfoAge();
		    List<String> dshoursums = dsllDAO.dsHourSum();		
		    //logger.info("Age is : " + dsinfoage );
		    
		    model.addObject("infoage", dsinfoage);
		    model.addObject("servicetypes", dsservicetypename);
		    model.addObject("numsessions", dsnumsessions);
		    model.addObject("drivernames", dsdrivernames);
		    model.addObject("enginenames", dsenginenames);
		    model.addObject("query", listDsll);
		    model.addObject("time", s.getTotalTimeMillis());
		    model.addObject("hoursums", dshoursums);
		    model.setViewName("test");
		 
		    return model;
		}
}
